/*
 * @Author: Tendo 
 * @Date: 2021-11-24 20:53:45 
 * @Last Modified by: Tendo
 * @Last Modified time: 2021-11-24 21:02:33
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
 var wiggleMaxLength = function (nums) {
    if (nums.length <= 1) return nums.length
    let curDiff = 0 // 当前一对差值
    let preDiff = 0 // 前一对差值
    let res = 1 // 记录峰值个数，序列默认序列最右边有一个峰值
    for (let i = 0; i < nums.length - 1; i++) {
        curDiff = nums[i + 1] - nums[i]
        // 出现峰值
        if ((curDiff > 0 && preDiff <= 0) || (preDiff >= 0 && curDiff < 0)) {
            res++;
            preDiff = curDiff;
        }
    }
    return res
};